﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HiStaff.Util;
using HiStaff.Base;
using HiStaff.Control;
using HiStaff.Domain.Sys;
using HiStaff.Util.Enum;
using System.Collections;
using HiStaff.Domain.PA;
using HiStaff.iSystem;

namespace HiStaff.iPay
{
    public partial class GroupFormular : FormBase
    {
        Formular fml;
        public GroupFormular()
        {
            InitializeComponent();
        }
        protected override bool FormLoad()
        {
            base.AddBasicCommandBar();
            InitControl();
            BindData();
            return base.FormLoad();
        }
        private void BindData()
        {
            grdData.DataSource = Service.PayrollClient.GetFormular();
            grdData.Refresh();
        }
        private void InitControl()
        {
            List<SY_DEFAULT_LIST> lstSource;

            lstSource = ConvertHelper.DataTableToList<SY_DEFAULT_LIST>((DataTable)cboType.DataSource);
            grdData.RootTable.Columns["PATYPE"].ValueList.PopulateValueList(lstSource, "ID", "NAME");

            lstSource = ConvertHelper.DataTableToList<SY_DEFAULT_LIST>((DataTable)cboSalGroup.DataSource);
            grdData.RootTable.Columns["SALGROUP"].ValueList.PopulateValueList(lstSource, "ID", "NAME");
        }
        private void grdData_SelectionChanged(object sender, EventArgs e)
        {
            BindDataFromGridToForm(grdData, this);
        }
        protected override bool SaveButtonClick()
        {
            var objSave = new PA_FML();
            ValueControlsToObject(objSave, this);
            if (Service.ExcuteStoreNonQuery("APRU_PA_FML", objSave))
            {
                MessageBox.Show(GetMessageById(Constant.MSG_TRANSACTION_SUCCESSFUL), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                BindData();
                return true;
            }
            return false;
        }
        protected override bool DeleteButtonClick()
        {
            var objDel = new PA_FML();
            ValueControlsToObject(objDel, this);
            if (Service.ExcuteStoreNonQuery("APRD_PA_FML", objDel))
            {
                MessageBox.Show(GetMessageById(Constant.MSG_TRANSACTION_SUCCESSFUL), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                BindData();
                return true;
            }
            return false;
        }
        protected override bool CancelButtonClick()
        {
            BindDataFromGridToForm(grdData, this);
            return base.CancelButtonClick();
        }

        private void grdData_RowDoubleClick(object sender, Janus.Windows.GridEX.RowActionEventArgs e)
        {
            if (e.Row.RowType == Janus.Windows.GridEX.RowType.Record)
            {
                if (fml == null || fml.IsDisposed)
                {
                    fml = new Formular();
                }
                fml.FMLID = ((PA_FML)e.Row.DataRow).ID;
                fml.Show();
                fml.Activate();
            }
        }
    }
}
